package com.srd.phone.fragment;

import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.RadioButton;

import com.handmark.pulltorefresh.library.PullToRefreshBase;
import com.handmark.pulltorefresh.library.PullToRefreshListView;
import com.shengrongdai.srd.R;
import com.srd.phone.activity.TenderZqInvestActivity;
import com.srd.phone.adapter.TabTenderListZqAdapter;
import com.srd.phone.bean.TenderInfo;
import com.srd.phone.mvp.presenters.BasePresenter;
import com.srd.phone.utils.Constants;
import com.srd.phone.utils.LogUtils;
import com.srd.phone.utils.views.FlowRadioGroup;

import java.util.ArrayList;
import java.util.List;

/**
 * 主界面  标的列表  债权 fragment
 */
public class TabTenderListZhaiquanFragment extends BaseFragment implements PullToRefreshBase.OnRefreshListener2 {

    private String url = Constants.BASEURL + "bmarkapp/bmarkList";

    private View viewRoot;
    private PullToRefreshListView pullToRefreshListView;
    private FlowRadioGroup rg_zq_annual_yield;
    private RadioButton rb_zq_annual_yield_no;
    private RadioButton rb_zq_annual_yield_10;
    private RadioButton rb_zq_annual_yield_20;
    private RadioButton rb_zq_annual_yield_20_up;
    private FlowRadioGroup rg_principal;
    private RadioButton rb_principal_1000;
    private RadioButton rb_principal_2000;
    private RadioButton rb_principal_2000_up;


    private TabTenderListZqAdapter adapter;
    private List<TenderInfo> list = new ArrayList<>();

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
    }

    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        if (viewRoot == null) {
            viewRoot = getParentView(inflater, container, R.layout.fragment_tab_tender_list_item);
            initView();
            initData();
        }
        return viewRoot;
    }

    @Override
    public void setUserVisibleHint(boolean isVisibleToUser) {
        super.setUserVisibleHint(isVisibleToUser);
    }

    @Override
    public void initView() {
        pullToRefreshListView = (PullToRefreshListView) viewRoot.findViewById(R.id.pull_refresh_list);
        View headView = getActivity().getLayoutInflater().inflate(R.layout.fragment_tab_tender_list_item_zq, null);
        pullToRefreshListView.getRefreshableView().addHeaderView(headView);
        rg_zq_annual_yield = (FlowRadioGroup) viewRoot.findViewById(R.id.rg_zq_annual_yield);
        rg_principal = (FlowRadioGroup) viewRoot.findViewById(R.id.rg_principal);
        pullToRefreshListView.setMode(PullToRefreshBase.Mode.BOTH);
        pullToRefreshListView.setOnLastItemVisibleListener(new PullToRefreshBase.OnLastItemVisibleListener() {
            @Override
            public void onLastItemVisible() {
            }
        });
        pullToRefreshListView.setOnRefreshListener(this);
        pullToRefreshListView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                mContext.startActivity(new Intent(mContext, TenderZqInvestActivity.class));
            }
        });
    }

    @Override
    public void initData() {
        presenter = new BasePresenter(requestQueue, this);
        setUrlArrs(url);
        adapter = new TabTenderListZqAdapter(mContext);
        list.add(new TenderInfo());
        list.add(new TenderInfo());
        list.add(new TenderInfo());
        list.add(new TenderInfo());
        list.add(new TenderInfo());
        list.add(new TenderInfo());
        adapter.setData(list);
        pullToRefreshListView.setAdapter(adapter);
    }

    @Override
    public void returnData(String tag, String data) {
        super.returnData(tag, data);
        if (getActivity().isFinishing())
            return;
        LogUtils.i(TabTenderListLicaiFragment.class, tag + "   " + data);
    }

    @Override
    public void onPullDownToRefresh(PullToRefreshBase refreshView) {

    }

    @Override
    public void onPullUpToRefresh(PullToRefreshBase refreshView) {

    }

}
